In this vignette we observe how plotly can be used to animate plots which can be a great way to visualize changes in a dataset. Here i use it to visualize changes in genres of the top selling games across the years 2000 to 2015. You can either click play to automatically run through the years, or use the slider.
library(plotly)
library(dplyr)
vgsales <- read.csv("https://raw.githubusercontent.com/jerryjerald27/Data-607/refs/heads/main/Tidyverse/vgsales.csv")
vgsales_filtered <- vgsales %>% filter(Year >= 2000 & Year <= 2015)
plot_ly(data = vgsales_filtered,
x = ~Global_Sales,
y = ~Genre,
color = ~Genre,
frame = ~Year,
type = 'bar',
orientation = 'h',
marker = list(line = list(width = 10))) %>%
layout(
xaxis = list(title = 'Global Sales (millions)'),
yaxis = list(title = 'Game Genre'),
title = 'Top Selling Game Genres (2000 to Present)',
updatemenus = list(
list(
type = 'buttons',
showactive = FALSE,
buttons = list(
list(method = 'animate', args = list(NULL, list(frame = list(duration = 1000, redraw = TRUE), mode = 'immediate')))
)
)
)
)
library(gt)
genre_summary <- vgsales_filtered |>
group_by(Genre) |>
summarise(
Average_Sales = round(mean(Global_Sales, na.rm = TRUE), 2),
Max_Sales = max(Global_Sales, na.rm = TRUE),
Min_Sales = min(Global_Sales, na.rm = TRUE),
Games_Count = n()
) |>
arrange(desc(Average_Sales))
genre_summary |>
gt() |>
tab_header(
title = "Summary of Global Sales by Game Genre (2000–2015)"
)
| Summary of Global Sales by Game Genre (2000–2015) | ||||
| Genre | Average_Sales | Max_Sales | Min_Sales | Games_Count |
|---|---|---|---|---|
| Shooter | 0.81 | 14.76 | 0.01 | 1083 |
| Platform | 0.70 | 30.01 | 0.01 | 708 |
| Sports | 0.58 | 82.74 | 0.01 | 1939 |
| Role-Playing | 0.57 | 18.36 | 0.01 | 1248 |
| Racing | 0.55 | 35.82 | 0.01 | 1015 |
| Action | 0.52 | 21.40 | 0.01 | 2905 |
| Fighting | 0.50 | 13.04 | 0.01 | 625 |
| Misc | 0.46 | 29.02 | 0.01 | 1568 |
| Simulation | 0.45 | 24.76 | 0.01 | 752 |
| Puzzle | 0.29 | 15.30 | 0.01 | 481 |
| Strategy | 0.21 | 4.83 | 0.01 | 538 |
| Adventure | 0.16 | 5.55 | 0.01 | 1143 |